package ctgu.yao.cloud.controller;

import ctgu.yao.cloud.dto.ResultDTO;
import ctgu.yao.cloud.po.Education;
import ctgu.yao.cloud.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ctgu.yao.cloud.po.Education;
import ctgu.yao.cloud.util.ResultDTOUtil;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Y
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/education")
public class EducationController {
    @Autowired
    private EducationService educationService;
    @RequestMapping("list")
    //查全部
    public List<Education> list(){
        return educationService.list();
    }

    //学历信息修改
    @RequestMapping("/findById/{id}")
    public ResultDTO findByID(@PathVariable("id") Integer id){
        Education education = this.educationService.getById(id);
        if(education==null&&id!=null){
            Education education1 = new Education();
            education1.setRid(id);
            education1.setEid(id);
            this.educationService.insert(education1);
            return ResultDTOUtil.success(education1);
        }
        return ResultDTOUtil.success(education);
    }
    @PutMapping("/update")
    public ResultDTO update(@RequestBody Education education){
        boolean update=this.educationService.updateById(education);
        if(!update) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }
}
